/*
Copyright 2005  Vitaliy Shevchuk (shevit@users.sourceforge.net)
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
   -----------------------------------
  | Modify By ZhangAoxiang in 2007/12 |
  | secyaher@163.com   271001331      |
  | http://secyaher.blog.163.com      |
   -----------------------------------
*/

AjaxAnywhere.defaultInstanceName = "default";

// constructor;    //构造 AjaxAnywhere 类
function AjaxAnywhere() 
{
    this.id = AjaxAnywhere.defaultInstanceName;
    this.formName = null;
    this.notSupported = false;
    this.delayBeforeContentUpdate = true;
    this.delayInMillis = 100;
    //no AAFilter
    this.noFilter = false;
    if (window.XMLHttpRequest) 
    {
        this.req = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject) 
    {
        try 
        {
            this.req = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch(e) 
        {
            try 
            {
                this.req = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch(e1) 
            {
                this.notSupported = true;      /* XMLHTTPRequest not supported  客户浏览器不支持 XMLHTTPRequest 此后另作处理*/
            }
        }
    }

    if (this.req == null || typeof this.req == "undefined")
        this.notSupported = true;
}

/**
* Stores substitutes SubmitButton names in to redo sustitution if a button was eventually inside a refresh zone.
*/
AjaxAnywhere.prototype.substitutedSubmitButtons = new Array();
AjaxAnywhere.prototype.substitutedSubmitButtonsInfo = new Object();

/**
* Returns a Form object that corresponds to formName property of this AjaxAnywhere class instance.
* 返回一个Form表单对象,来对应 AjaxAnywhere 实例的 formName 属性
*/
AjaxAnywhere.prototype.findForm = function () 
{
    var form;
    if (this.formName != null)
        form = document.forms[this.formName];
    else if (document.forms.length > 0)
        form = document.forms[0];
    if (typeof form != "object")
    	X.Alert("表单 [" + this.formName + "] 未找到!");
    return form;
}
/**
* Binds this instance to window object using "AjaxAnywhere."+this.id as a key.
* 给 'window' 实例 绑定一个键值,键值为 'AjaxAnywhere.' + AjaxAnywhere 对象的id属性值 
*/
AjaxAnywhere.prototype.bindById = function () 
{
    var key = "AjaxAnywhere." + this.id;
    window[key] = this;
}
/**
* Finds an instance by id.
* 通过给定 id 值来找到 'window' 实例
*/
AjaxAnywhere.findInstance = function(id) 
{
    var key = "AjaxAnywhere." + id;
    return window[key];
}
/**
* This function is used to submit all form fields by AJAX request to the server.
* 此方法用来提交所有表单数据,以 AJAX 异步请求到服务器(即:无刷新请求)   -- POST 请求
* If the form is submited with &lt;input type=submit|image&gt;, submitButton should be a reference to the DHTML object. Otherwise - undefined.
* 如果表单提交定义时以'submit'方式或是'image'按钮方式,那么数据提交过程将采用 DHTML方式提交而不用 AJAX 方式提交  , 其它情况,没有定义(当没有定义<aa:zone>刷新区域时,也将采用原始方法)
*/
AjaxAnywhere.prototype.submitAJAX = function(additionalPostData, submitButton) 
{
    if (this.notSupported)
        return this.onSubmitAjaxNotSupported(additionalPostData, submitButton);

    if (additionalPostData == null || typeof additionalPostData == "undefined")
        additionalPostData = "";

    this.bindById();

    var form = this.findForm();

    var actionAttrNode = form.attributes["action"];
    var url = actionAttrNode == null?null:actionAttrNode.nodeValue;
    if ((url == null) || (url == ""))
        url = location.href;

    var pos = url.indexOf("#");
        if (pos!=-1)
            url = url.substring(0,pos);
        if ((url == null) || (url == ""))
            url = location.href;
        pos = url.indexOf("#");
        if (pos!=-1)
            url = url.substring(0,pos);

    var zones = this.getZonesToReload(url, submitButton);

    if (zones == null) 
    {
        // submit in tradiditional way :
        this.submitOld(form,submitButton)
        return;
    }

    this.dropPreviousRequest();

    this.req.open("POST", url, true);
    this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");

    var postData = this.preparePostData(submitButton);

    if (zones != "")
        postData = '&aazones=' + encodeURIComponent(zones) + "&" + postData + "&" + additionalPostData;
    else
        postData += "&" + additionalPostData;

    this.sendPreparedRequest(postData);

}
/**
* sends a GET request to the server.
* 采用 AJAX  GET方式发送请求到服务器
*/
AjaxAnywhere.prototype.getAJAX = function(url, zonesToRefresh) 
{
    if (this.notSupported)
        return this.onGetAjaxNotSupported(url);

    this.bindById();

    if (zonesToRefresh == null || typeof zonesToRefresh == "undefined")
        zonesToRefresh = "";
    var urlDependentZones = this.getZonesToReload(url);
    if (urlDependentZones == null) 
    {
        location.href = url;
        return;
    }

    if (urlDependentZones.length != 0)
        zonesToRefresh += "," + urlDependentZones;

    this.dropPreviousRequest();

    url += (url.indexOf("?") != -1) ? "&" : "?";

    url += "aaxmlrequest=true&aa_rand=" + Math.random();
    // avoid caching

    if (zonesToRefresh != null && zonesToRefresh != "")
        url += '&aazones=' + encodeURIComponent(zonesToRefresh);
    this.req.open("GET", url, true);

    this.sendPreparedRequest("");
}

/**
* @private
* 私有方法,请求发送
*/
AjaxAnywhere.prototype.sendPreparedRequest = function (postData) 
{
    this.req.setRequestHeader("Accept", "text/xml");
    var callbackKey = this.id + "_callbackFunction";
    if (typeof window[callbackKey] == "undefined")
        window[callbackKey] = new Function("AjaxAnywhere.findInstance(\"" + this.id + "\").callback(); ");
    this.req.onreadystatechange = window[callbackKey];

    this.showLoadingMessage();

    this.req.send(postData);

    this.onRequestSent();
}
/**
* Used internally by AjaxAnywhere. Aborts previous request if not completed.
* 在 AjaxAnywhere 内部使用,用来取消请求,如果,请求还没有被完成的话
*/
AjaxAnywhere.prototype.dropPreviousRequest = function() 
{
    if (this.req.readyState != 0 && this.req.readyState != 4) 
    {
        // abort previous request if not completed
        this.req.abort();
        this.handlePrevousRequestAborted();
    }
}

/**
* Internally used to prepare Post data.
* 内部使用来做数据发送准备
* If the form is submited with &lt;input type=submit|image&gt;, submitButton is a reference to the DHTML object. Otherwise - undefined.
* 如果表单提交定义时以'submit'方式或是'image'按钮方式,那么数据提交过程将采用 DHTML方式提交而不用 AJAX 方式提交  , 其它情况,没有定义
*/
AjaxAnywhere.prototype.preparePostData = function(submitButton) 
{
    var form = this.findForm();
    var result = this.noFilter?"":"&aaxmlrequest=true";
    for (var i = 0; i < form.elements.length; i++) 
    {
        var el = form.elements[i];
        if (el.tagName.toLowerCase() == "select") 
        {
            for (var j = 0; j < el.options.length; j++) 
            {
                var op = el.options[j];
                if (op.selected)
                    result += "&" + encodeURIComponent(el.name) + "=" + encodeURIComponent(op.value);
            }
        }
        else if (el.tagName.toLowerCase() == "textarea") 
        {
            result += "&" + encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value);
        } 
        else if (el.tagName.toLowerCase() == "input") 
        {
            if (el.type.toLowerCase() == "checkbox" || el.type.toLowerCase() == "radio") 
            {
                if (el.checked)
                    result += "&" + encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value);
            } 
            else if (el.type.toLowerCase() == "submit") 
            {
                if (el == submitButton) // is "el" the submit button that fired the form submit?
                    result += "&" + encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value);
            } 
            else if (el.type.toLowerCase() != "button") 
            {
                result += "&" + encodeURIComponent(el.name) + "=" + encodeURIComponent(el.value);
            }
        }
    }
    if (typeof submitButton != 'undefined' && submitButton != null && submitButton.type.toLowerCase() == "image") 
    {
        if (submitButton.name == null || submitButton.name == "" || typeof submitButton.name == "undefined")
            result += "&x=1&y=1"; // .x and .y coordinates calculation is not supported.
        else
            result += "&" + encodeURIComponent(submitButton.name) + ".x=1&" +
                      encodeURIComponent(submitButton.name) + ".y=1";
    }
    return result;
}

/**
* Pauses the thread of execution for the specified number of milliseconds
* @private
* 中止正在执行的线程,在指定的毫秒数
*/
function delay(millis) 
{
    date = new Date();
    var curDate = null;
    do 
    {
        curDate = new Date();
    }
    while (curDate - date < millis);
}

/**
* A callback. internally used
* 回调,内部使用
*/
AjaxAnywhere.prototype.callback = function() 
{
    if (this.req.readyState == 4) 
    {
        this.onBeforeResponseProcessing();
        this.hideLoadingMessage();

        if (this.req.status == 200) 
        {
        	var xmessage = this.req.getResponseHeader('xmessage');
        	if(xmessage)
        	{
        		xmessage = unescape(xmessage);
        		var result = xmessage.substring(0,1);
        		var message = xmessage.substring(2);
        		if(result == '1')
        		{
        			X.Alert(message,'X.CloseLayer');
        			parent.X.Search();
        		}
        		else if(result == '0')
        		{
        			X.Alert(message);
        		}
        		return;
        	}
        	
            if (this.req.getResponseHeader('content-type').toLowerCase().substring(0, 8) != 'text/xml')
            	X.Alert("返回文档类型非 text/xml，点击<a href='"+x.ContextPath+"/login.shtml' style='color:red'>重新登录后再试</a>");
           
            var docs = this.req.responseXML.getElementsByTagName("document");
            var redirects = this.req.responseXML.getElementsByTagName("redirect");
            var zones = this.req.responseXML.getElementsByTagName("zone");
            var exceptions = this.req.responseXML.getElementsByTagName("exception");
            var scripts = this.req.responseXML.getElementsByTagName("script");
            var images = this.req.responseXML.getElementsByTagName("image");

            if (redirects.length != 0) 
            {
                var newURL = redirects[0].firstChild.data;
                location.href = newURL;
            }
            if (docs.length != 0) 
            {
                var newContent = docs[0].firstChild.data;

                //cleanup ressources
                delete this.req;

                document.close();
                document.write(newContent);
                document.close();
            }

            if (images.length != 0) 
            {
                var preLoad = new Array(images.length);
                for (var i = 0; i < images.length; i++) 
                {
                    var img = images[i].firstChild;
                    if (img != null) 
                    {
                        preLoad[i] = new Image();
                        preLoad[i].src = img.data;
                    }
                }
                if (this.delayBeforeContentUpdate) 
                {
                    delay(this.delayInMillis);
                }
            }

            if (zones.length != 0) 
            {
                for (var i = 0; i < zones.length; i++) 
                {
                    var zoneNode = zones[i];

                    var name = zoneNode.getAttribute("name");
                    var id = zoneNode.getAttribute("id");

                    var html = "";

                    for (var childIndex = 0; childIndex < zoneNode.childNodes.length; childIndex++) 
                    {
                        html += zoneNode.childNodes[childIndex].data
                    }

                    var zoneHolder = name!=null?document.getElementById("aazone." + name):document.getElementById(id);

                    if (zoneHolder != null && typeof(zoneHolder) != "undefined") 
                    {
                        zoneHolder.innerHTML = html;
                    }
                }
            }
            if (exceptions.length != 0) 
            {
                var e = exceptions[0];
                var type = e.getAttribute("type");
                var stackTrace = e.firstChild.data;
                this.handleException(type, stackTrace);
            }

            if (scripts.length != 0) 
            {
                for (var $$$$i = 0; $$$$i < scripts.length; $$$$i++) 
                {
                    // use $$$$i variable to avoid collision with "i" inside user script
                    var script = scripts[$$$$i].firstChild;
                    if (script != null) 
                    {
                        script = script.data;
                        if (script.indexOf("document.write") != -1) 
                        {
                            this.handleException("document.write", "This script contains document.write(), which is not compatible with AjaxAnywhere : \n\n" + script);
                        } 
                        else 
                        {
                            eval("var aaInstanceId = \""+this.id+"\"; \n"+script);
                        }
                    }
                }

                var globals = this.getGlobalScriptsDeclarationsList(script);
                if (globals != null)
                    for (var i in globals) 
                    {
                        var objName = globals[i];
                        try 
                        {
                            window[objName] = eval(objName);
                        } 
                        catch(e) 
                        {   }
                    }
            }

        } 
        else 
        {
            if (this.req.status != 0)
                this.handleHttpErrorCode(this.req.status);
            else
                this.handleHttpErrorCode("HTTP_REQ_STATUES_0");
        }
        this.restoreSubstitutedSubmitButtons();
        this.onAfterResponseProcessing();
    }
}

/**
*  Default sample loading message show function. Overrride it if you like.
*  默认 'loading' 消息提示 显示 函数, 当然,你也可以重载此函数,来自己定制个性消息提示
*/
AjaxAnywhere.prototype.showLoadingMessage = function() 
{
    var div = document.getElementById("AA_" + this.id + "_loading_div");
    if (div == null) 
    {
        div = document.createElement("DIV");

        document.body.appendChild(div);
        div.id = "AA_" + this.id + "_loading_div";

        div.innerHTML = "&nbsp;数据载入中&nbsp;&nbsp;<img src=\"\" alt=\"正在载入...\"/>";
        div.style.position = "absolute";
        div.style.filter="alpha(opacity=90)";  //IE透明度
		div.style.MozOpacity = 90/100;    //火狐透明度
        div.style.textAlign = "center";
        div.style.backgroundColor = "#f9f9f9";
        div.style.width = "300px";
        div.style.heigth = "150px";
        div.style.padding = "10px 0px 10px 0px";
        div.style.fontFamily = "Arial, Helvetica, sans-serif";
        div.style.fontWeight = "bold";
        div.style.fontSize = "18px";
        div.style.border = "1px solid #707070";
        div.style.zIndex = "10000";
    }
    div.style.left = "50%";
 	div.style.top = "50%";
 	div.style.marginLeft = -150 + "px";
 	div.style.marginTop = -150/2 + document.documentElement.scrollTop+"px";
    div.style.display = "";
}

/**
*  Default sample loading message hide function. Overrride it if you like.
*  默认 'loading' 消息提示 隐藏 函数, 当然,你也可以重载此函数,来自己定制个性消息提示
*/
AjaxAnywhere.prototype.hideLoadingMessage = function() 
{
    var div = document.getElementById("AA_" + this.id + "_loading_div");
    if (div != null)
        div.style.display = "none";
}

/**
* This function is used to facilitatte AjaxAnywhere integration with existing projects/frameworks.
* 此方法用来整合 AjaxAnywhere 框架 
* It substitutes default Form.sumbit().
* 它用来代替 默认的 Form.sumbit() 方法
* The new implementation calls AjaxAnywhere.isFormSubmitByAjax() function to find out if the form
* should be submitted in traditional way or by AjaxAnywhere.
* 这个新的结口用来调用 AjaxAnywhere.isFormSubmitByAjax() 方法,用判断,表单是否采用AJAX方式,还是原始方式提交
*/
AjaxAnywhere.prototype.substituteFormSubmitFunction = function() 
{
    if (this.notSupported)
        return;

    this.bindById();

    var form = this.findForm();

    form.submit_old = form.submit;
    var code = "var ajax = AjaxAnywhere.findInstance(\"" + this.id + "\"); " +
               "if (typeof ajax !='object' || ! ajax.isFormSubmitByAjax() ) " +
               "ajax.findForm().submit_old();" +
               " else " +
               "ajax.submitAJAX();"
    form.submit = new Function(code);                //此处采用匿名函数,函数代码为 code  ,太有创意了,javascript太神奇了... 
}
/**
* Substitutes the default behavior of &lt;input type=submit|image&gt; to submit the form via AjaxAnywhere.
* 替代所有 'type' 值为submit,image的按钮的行为,用来使表单提交使用AJAX方式
* @param {boolean} indicates if existing onClick handlers should be preserved.     //第一个参数 true | false
* 如果参数指出存在 'onClick' 事件,操作将会被保护
* If keepExistingOnClickHandler==true,
* Existing handler will be called first if it returns false, or if event.returnValue==false, AjaxAnywhere will not
* continue form submission.
* 如果存在的事件先被调用返回值为 false,或者 ,事件的值为 false ,AjaxAnywhere 就不会再继续执行表单行为
* If keepExistingOnClickHandler==false or undefines, existing onClick event handlers will be replaced.
* 如果参数值是 false,或是 没有定义, 那么, 'onClick'  事件将会被移除
* @param {Array} list of submitButtons and submitImages names. If the parameter is omitted or undefined,  //第二个参数 数组
* all elements will be processed
* 些参数存放所有 提交按钮或是提交型图片按钮的名字,如果些参数省略或是没有定义,那么,此处将会重新组织这些数据
*/
AjaxAnywhere.prototype.substituteSubmitButtonsBehavior = function (keepExistingOnClickHandler, elements) 
{
    if (this.notSupported)
        return;

    var form = this.findForm();
    if (elements == null || typeof elements == "undefined") 
    {   // process all elements
        elements = new Array();
        for (var i = 0; i < form.elements.length; i++) 
        {
            elements.push(form.elements[i]);
        }

        var inputs = document.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) 
        {
            var input = inputs[i];
            if (input.type != null && typeof input.type != "undefined" &&
                input.type.toLowerCase() == "image" && input.form == form) 
            {
                elements.push(input);
            }
        }

        for (var i = 0; i < elements.length; i++) 
        {
            var el = elements[i];
            if (el.tagName.toLowerCase() == "input" && (el.type.toLowerCase() == "submit"
                    || el.type.toLowerCase() == "image")) 
            {
                this.substituteSubmitBehavior(el, keepExistingOnClickHandler);
            }
        }
    } 
    else 
    {   //process only specified elements
        for (var i = 0; i < elements.length; i++) 
        {
            var el = elements[i];
            if (el == null)
                continue;

            if (typeof el != "object")
                el = form.elements[el];

            if (typeof el != "undefined") 
            {
                if (el.tagName.toLowerCase() == "input" && (el.type.toLowerCase() == "submit"
                        || el.type.toLowerCase() == "image"))
                    this.substituteSubmitBehavior(el, keepExistingOnClickHandler);
            }
        }
    }

}
/**
* Performs a single element behavior substitution
* 运行 一个单例的提交行为
* @private
*/
AjaxAnywhere.prototype.substituteSubmitBehavior = function (el, keepExistingOnClickHandler) 
{
    var inList = false;
    for (var i = 0; i < this.substitutedSubmitButtons.length; i++) 
    {
        var btnName = this.substitutedSubmitButtons[i];
        if (btnName == el.name) 
        {
            inList = true;
            break;
        }
    }
    if (!inList)
        this.substitutedSubmitButtons.push(el.name);

    this.substitutedSubmitButtonsInfo[el.name] = keepExistingOnClickHandler;

    if (keepExistingOnClickHandler && (typeof el.onclick != "undefined") && ( el.onclick != null) && ( el.onclick != "")) 
    {
        el.AA_old_onclick = el.onclick;
    }

    el.onclick = handleSubmitButtonClick;
    el.ajaxAnywhereId = this.id;
}

/**
* @private
*/
AjaxAnywhere.prototype.restoreSubstitutedSubmitButtons = function() 
{
    if (this.substitutedSubmitButtons.length == 0)
        return;

    var form = this.findForm();

    for (var i = 0; i < this.substitutedSubmitButtons.length; i++) 
    {
        var name = this.substitutedSubmitButtons[i];
        var el = form.elements[name];
        if (el != null && typeof el != "undefined") 
        {
            if (el.onclick != handleSubmitButtonClick) 
            {
                var keepExistingOnClickHandler = this.substitutedSubmitButtonsInfo[el.name];
                this.substituteSubmitBehavior(el, keepExistingOnClickHandler);
            }
        } 
        else 
        {
            //input type=image
            if (name != null && typeof name != "undefined" && name.length != 0) 
            {
                var elements = document.getElementsByName(name);
                if (elements != null)
                    for (var j = 0; j < elements.length; j++) 
                    {
                        el = elements[j];
                        if (el != null && typeof el != "undefined"
                                && el.tagName.toLowerCase() == "input"
                                && typeof el.type != "undefined" && el.type.toLowerCase() == "image") 
                        {
                            if (el.onclick != handleSubmitButtonClick) 
                            {
                                var keepExistingOnClickHandler = this.substitutedSubmitButtonsInfo[el.name];
                                this.substituteSubmitBehavior(el, keepExistingOnClickHandler);
                            }
                        }
                    }
            }
        }
    }
}

/**
* @private
*/
function handleSubmitButtonClick(_event) 
{
    if (typeof this.AA_old_onclick != "undefined") 
    {
        if (false == this.AA_old_onclick(_event))
            return false;
        if (typeof window.event != "undefined")
            if (window.event.returnValue == false)
                return false;
    }
    var onsubmit = this.form.onsubmit;
    if (typeof onsubmit == "function") 
    {
        if (false == onsubmit(_event))
            return false;
        if (typeof window.event != "undefined")
            if (window.event.returnValue == false)
                return false;
    }
    AjaxAnywhere.findInstance(this.ajaxAnywhereId).submitAJAX('', this);

    return false;
}
/**
* Override this function if you use AjaxAnywhere.substituteFormSubmitFunction() to
* dynamically inform AjaxAnywhere of the method you want to use for the form submission.
*/
AjaxAnywhere.prototype.isFormSubmitByAjax = function () {
    return true;
}

/**
* Some browsers (notably IE) do not load images from thier cache when content is updated using
* innerHTML. As a result, each image is re-requested from the server even though the image exists
* in the cache. To work around this issue, AjaxAnywhere preloads images present in the new content
* and intrduces a brief dely (default of 100 milleseconds) before calling innerHTML.
* See http://support.microsoft.com/default.aspx?scid=kb;en-us;319546 for further details.
* This function can be used to change this behaviour.
* @param (boolean) isDelay
*/
AjaxAnywhere.prototype.setDelayBeforeLoad = function (isDelay) {
    this.delayBeforeContentUpdate = isDelay;
}

/**
* Returns the current delay behavior.
*/
AjaxAnywhere.prototype.isDelayBeforeLoad = function () {
    return this.delayBeforeContentUpdate;
}

/**
* Sets the delay period in milliseconds. The default delay is 100 milliseconds.
* @param (int) delayMillis
*/
AjaxAnywhere.prototype.setDelayTime = function (delayMillis) {
    this.delayInMillis = delayMillis;
}

/**
* Returns the delay period in milliseconds.
*/
AjaxAnywhere.prototype.getDelayTime = function () {
    return this.delayInMillis;
}

/**
*   If an exception is throws on the server-side during AJAX request, it will be processed
* by this function. The default implementation is alert(stackTrace);
* Override it if you need.
*/
AjaxAnywhere.prototype.handleException = function(type, details) {
    X.Alert("服务器异常:" + details + "");
}
/**
*   If an HTTP Error code returned during AJAX request, it will be processed
* by this function. The default implementation is alert(code);
* Override it if you need.
*  当运行AJAX请求发生 HTTP 错误时,将会被此函数处理加工,默认会弹出 错误代码,当然你也可以重写此方法
*/
AjaxAnywhere.prototype.handleHttpErrorCode = function(code) 
{
	if(code=="HTTP_REQ_STATUES_0")
	{
		X.Alert("登录超时，点击<a href='"+X.ContextPath+"/login.shtml' style='color:red'>重新登录</a>");
	}
	else if(code=="HTTP_REQ_NOT_TEXT/XML")
	{
		X.Alert("返回文档类型非 text/xml，点击<a href='"+X.ContextPath+"/login.shtml' style='color:red'>重新登录后再试</a>");
	}
	else if(code=="403")
	{
		X.Alert("非法操作,本次操作已记录！");
	}
	else
	{
		//HTTP 异常处理
		X.Alert("产生HTTP Error:" + code + "");
	}
}

/**
* Override it if you need.
* 请求被放弃事件,(当前一请求未处理完成,再发送请求时触发),最好重写,定制个性的
*/
AjaxAnywhere.prototype.handlePrevousRequestAborted = function() 
{
	X.Alert("请稍候...上一请求正在处理...");
}
/**
*   If the HTML received in response to AJAX request contains JavaScript that defines new
* functions/variables, they must be propagated to the proper context. Override this method
* to return the Array of function/variable names.
*/
AjaxAnywhere.prototype.getGlobalScriptsDeclarationsList = function(script) 
{
    return null;
}

/**
* This function should be overridden by AjaxAnywhere user to implement client-side
* determination of zones to reload.
*
* If the form is submited with &lt;input type=submit|image&gt;, submitButton is a reference to the DHTML object. Otherwise - undefined.
*
* @Returns a comma separated list of zones to reload, or "document.all" to reload
* the whole page. Returns null if the request must be sent in traditional way
*
*/
AjaxAnywhere.prototype.getZonesToReload = function(url, submitButton) 
{
	
    return this.getZonesToReaload();
    // backward compatibility only
}
/**
* depreceted : wrond spelling : Reaload will be removed in later versions
*/
AjaxAnywhere.prototype.getZonesToReaload = function(url, submitButton) {
    return "";
}

/**
* Override this method to implement a custom action
* 接口: 定制 请求发送时 客户代码
*/
AjaxAnywhere.prototype.onRequestSent = function () {};
/**
* Override this method to implement a custom action
* 接口: 定制 请求结果返回前的 客户代码
*/
AjaxAnywhere.prototype.onBeforeResponseProcessing = function () {};
/**
* Override this method to implement a custom action
* 接口: 定制 请求结果返回后的 客户代码
*/
AjaxAnywhere.prototype.onAfterResponseProcessing = function () 
{
	X.CallBack();
};

/**
* Provides a default implementation from graceful degradation for getAJAX()
* calls location.href=url if XMLHttpRequest is unavailable, reloading the entire page .
* 当 GET 方式 AJAX请求不支持时,执行 页面跳转(会刷新)
*/
AjaxAnywhere.prototype.onGetAjaxNotSupported = function (url) 
{
    location.href = url;
    return false;
};
/**
* Provides a default implementation from graceful degradation for submitAJAX()
* calls form.submit() if XMLHttpRequest is unavailable, reloading the entire page
* 当 POST 方式执行 AJAX 请求不支持时,执行原始方式请求提交
*/
AjaxAnywhere.prototype.onSubmitAjaxNotSupported = function (additionalPostData, submitButton) 
{
    var form = this.findForm();
    var actionAttrNode = form.attributes["action"];
    var url = actionAttrNode == null?null:actionAttrNode.nodeValue;
    var url_backup = url;
    if (typeof additionalPostData != 'undefined' && additionalPostData != null) 
    {
        url += (url.indexOf("?") != -1) ? "&" : "?";
        url += additionalPostData;
        form.attributes["action"].nodeValue= url;
        // only POST method allows sending additional
        // date by altering form action URL.
        form.setAttribute("method", "post");
    }

    this.submitOld(form,submitButton);

    form.attributes["action"].nodeValue= url_backup;
    return false;
};
/**
* submit the form in tradiditional way :
* @private
* AJAX不支持时,原始请求方法 此处采用隐藏域 来人存储 传送 button提交按钮的属性值
*/

AjaxAnywhere.prototype.submitOld = function (form,submitButton)
{
    var submitHolder = null;
    if (submitButton!=null && typeof submitButton!="undefined"){
        submitHolder = document.createElement("input");
        submitHolder.setAttribute("type","hidden");
        submitHolder.setAttribute("name",submitButton.name);
        submitHolder.setAttribute("value",submitButton.value);
        form.appendChild(submitHolder);

    }

    if (typeof form.submit_old == "undefined")
        form.submit();
    else
        form.submit_old();

    if (submitButton!=null )
    {
        form.removeChild(submitHolder);
    }
}

// default instance.   //默认初始化 AjaxAnywhere 对象
ajaxAnywhere = new AjaxAnywhere();
ajaxAnywhere.bindById();